
 import java.util.*;

 public class MySort1 {
     public static void main(String [] args) {
         String [] toSort = {"aaa:10:1:1",
                             "ccc:30:3:4",
                             "bbb:50:4:5",
                             "ddd:20:5:3",
                             "eee:40:2:20"};

         System.out.println("Before sort:");
         for (String str: toSort)
                  System.out.println(str);

         Arrays.sort(toSort);
    
         System.out.println("After sort:");
         for( String str : toSort)
             System.out.println(str);
         
         
         System.out.println("After toSort:");
         int  [] tmp = new int [toSort.length];
         String [][] tmpp = new String[toSort.length][4];
        for (int i = 0; i< toSort.length; i++){
        	  tmpp[i] = toSort[i].split(":");
        	  tmp[i] = Integer.parseInt(tmpp[i][2]);
        	  
        	  }
        
        
        
        Arrays.sort(tmp);
        for (int i = 0; i < tmp.length; i++) {
            for (int j = 0; j < toSort.length; j++) {
                if(tmp[i] == Integer.parseInt(tmpp[j][2])){
                    System.out.println(toSort[j]);
                }
            }
        }
      
        
}
 }
